package com.qinghuan.designMode.prePrinciple.Demeter.improve;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: qinghuan
 * @Date: 2022/2/21 21:14
 * @Description:
 */
public class Demeter {

    public static void main(String[] args) {
        System.out.println("使用迪米特法则的改进~~~");
        TeacherManager teacherManager = new TeacherManager();
        teacherManager.PrintAllPerson(new StudentManager());
    }

}

class Student {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

class Teacher {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

class StudentManager {
    public List<Student> getAllStudent() {
        List<Student> list = new ArrayList<Student>();
        for (int i = 0; i < 10; i++) {
            Student student1 = new Student();
            student1.setId("学号是：id=" + i);
            list.add(student1);
        }
        return list;
    }

    public void printStudent() {
        List<Student> list = this.getAllStudent();
        System.out.println("------学生的学号为：");
        for (Student student : list) {
            System.out.println(student.getId());
        }
    }
}

class TeacherManager {
    public List<Teacher> getAllTeacher() {
        List<Teacher> list = new ArrayList<Teacher>();
        for (int i = 0; i < 5; i++) {
            Teacher teacher = new Teacher();
            teacher.setId("教师的id=" + i);
            list.add(teacher);
        }
        return list;
    }

    void PrintAllPerson(StudentManager stu) {

        stu.printStudent();

        System.out.println("--------教师的工号为：");
        List<Teacher> list1 = this.getAllTeacher();
        for (Teacher teacher : list1) {
            System.out.println(teacher.getId());
        }
    }

}